layui.use(['form','laydate'], function () {
    var form = layui.form;
    var laydate = layui.laydate;
    var id = getParam("id");
    //执行一个laydate实例
    laydate.render({
        elem: '#buyDate' //指定元素
    });
    laydate.render({
        elem: '#sellDate' //指定元素
    });
    form.render();
    var isAdd=true;
    if (!isNull(id)) {
    	isAdd=false;
    	io.get('/stock/trade/records/' + id,function(res){
    		form.val('editForm',res.data);
    	});
    }
    //监听提交
    form.on('submit(save)', function (formData) {
    	var data = JSON.stringify(formData.field);
    	if(isAdd){
    		io.post("/stock/trade/buy-records",data,function(res){
                //关闭当前页
                setTimeout(function(){return closePage();},500);
                //刷新列表
                window.parent.refreshTableData();
    		});
	    }else{
	    	io.post("/stock/trade/records",data,function(res){
                //关闭当前页
                setTimeout(function(){return closePage();},500);
                //刷新列表
                window.parent.refreshTableData();
	        });
	    }
        return false;
    });
});

